<template>
  <div class="input-com">
    <div class="input-key">
      <input
             @keyup.enter="searchClick()"
             v-model.trim="commom"
             @blur="searchBlur"
             :placeholder="holder"
             :style="{'width': `${width}px`, 'height': `${height}px`, background: background, borderColor: borderColor}">
      <i class="iconfont icon-sousuo" @click="searchClick()" :style="{top: `${searchTop}px`}"></i>
      <!--<button class="button-blue" @click="searchClick()">搜索</button>-->
    </div>
  </div>
</template>

<script>
  export default {
    name: 'zz-search',
    data () {
      return {
        show: false,
        commom: ''
      }
    },
    props: {
      holder: {
        type: String,
        default: '输入搜索条件'
      },
      width: {
        type: Number,
        default: 180
      },
      height: {
        type: Number,
        default: 30
      },
      background: {
        type: String,
        default: ''
      },
      borderColor: {
        type: String,
        default: ''
      },
      searchTop: {
        type: Number,
        default: 1
      },
      // 恢复默认
      resetPlace: {
        type: Number,
        default: 0
      }
    },
    watch: {
      resetPlace () {
        this.commom = ''
      }
    },
    methods: {
      searchClick () {
        this.$emit('searchClick', this.commom)
      },
      searchBlur () {
        if (this.commom === '') {
          this.$emit('searchClick', '')
        } else {
          this.$emit('watchCommon', this.commom)
        }
      }
    }
  }
</script>

<style lang="scss" scoped>
  .input-com{
    display: inline-block;
    .input-key{
      display: inline-block;
      position: relative;
      margin-right: 5px;
      line-height: 30px;
      &:last-child{
        margin:0;
      }
      input{
        @include input-l;
      }
      .icon-sousuo{
        position: absolute;
        right: 7px;
        font-size: 14px;
        color: $color-grid;
        cursor: pointer;
        &:hover{
          color: $color;
        }
      }
    }
    &:last-child{
      margin: 0;
    }
  }
</style>
